package com.yzd.learnjava.io;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Date;
import java.util.concurrent.TimeUnit;

import com.yzd.learnjava.util.Print;

public class Logon implements Serializable{
	private Date date = new Date();
	private String username ;
	private transient String pwd ;
	public Logon(String pwd , String name) {
		username = name;
		this.pwd = pwd;
	}
	
	public String toString() {
		return "logon info : \n   username : " + username + "\n   pwd : " + pwd + "\n   date : " + date;
	}
	
	public static void main(String[] args) throws Exception, IOException {
		Logon a = new Logon("mypwd", "Hulk");
		Print.print("Logon a = " + a);
		
		ObjectOutputStream o = new ObjectOutputStream(new FileOutputStream("Logon.out"));
		o.writeObject(a);
		o.close();
		
		TimeUnit.SECONDS.sleep(1);
		ObjectInputStream in = new ObjectInputStream(new FileInputStream("Logon.out"));
		Print.print("Recovering object at " + new Date());
		a = (Logon)in.readObject();
		Print.print("logon a = " + a);
		
	}
}
